<?php

class Silk_Pms_Model_Gift extends Mage_Core_Model_Abstract
{
	private $_giftProduct = null;

	protected function _construct()
	{
       	$this->_init("pms/gift");
    }

	public function getTip()
	{
		$tip = $this->getData('tip');
		if(!$tip)
		{
			$tip = "买{$this->getDiscountStep()}赠{$this->getDiscountQty()},赠品：{$this->getGiftProductName()}";
		}
		return $tip;
	}

	public function getGiftProduct()
	{
		if(is_null($this->_giftProduct))
		{
			$this->_giftProduct = Mage::getModel('catalog/product')->load($this->getGiftProductId());
		}
		return $this->_giftProduct;
	}

	public function isValidate()
	{
		if(!$this->getStatus())
		{
			return false;
		}

		$now = Mage::getModel('core/date')->date('Y-m-d');
		if(strtotime($this->getFromDate())>strtotime($now))
		{
			return false;
		}
		if(strtotime($this->getToDate())<strtotime($now))
		{
			return false;
		}

		if($this->getUsedQty()>$this->getGiftQty())
		{
			return false;
		}

		return true;
	}
}